package com.example.common;


import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import java.sql.SQLIntegrityConstraintViolationException;

@ControllerAdvice(annotations = RestController.class)
@ResponseBody
public class GlobalException {


    @ExceptionHandler(SQLIntegrityConstraintViolationException.class)
    public R<String> handleException(SQLIntegrityConstraintViolationException e) {

        if(e.getMessage().equals("Duplicate entry")){
            return R.error("该名称已存在！");
        }

        return R.error(e.getMessage());
    }


    @ExceptionHandler(CustomerException.class)
    public R<String> handleException2(CustomerException e) {



        return R.error(e.getMessage());
    }
}
